package view;

import control.FormulasCreator;
import javax.swing.JOptionPane;
import model.IFormula;


public class PrincipalMDI extends javax.swing.JFrame {
    //Usamos singleton para garantir que as isntacias serão unica
     Sobre sobreForm = Sobre.getInstance();
     QuadradoForm quadradoForm = QuadradoForm.getInstance();
     CirculoForm circuloForm = CirculoForm.getInstance();
     TrianguloForm trianguloForm = TrianguloForm.getInstance();
     RetanguloForm retanguloForm = RetanguloForm.getInstance();
     
    /** Creates new form PrincipalMDI */
    public PrincipalMDI() {
        initComponents();
        this.setResizable(false);
        this.setTitle("CALCULO DE ÁREAS PARA FIGURAS GEOMETRICAS");
        desktopPane.add(sobreForm);
        desktopPane.add(quadradoForm);
        desktopPane.add(circuloForm);
        desktopPane.add(trianguloForm);
        desktopPane.add(retanguloForm);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        desktopPane = new javax.swing.JDesktopPane();
        menuBar = new javax.swing.JMenuBar();
        calcularMenu = new javax.swing.JMenu();
        quadradoMenuItem = new javax.swing.JMenuItem();
        retanguloMenuItem = new javax.swing.JMenuItem();
        trianguloMenuItem = new javax.swing.JMenuItem();
        circuloMenuItem = new javax.swing.JMenuItem();
        exitMenuItem = new javax.swing.JMenuItem();
        ajudaMenu = new javax.swing.JMenu();
        formulasMenuItem = new javax.swing.JMenuItem();
        sobreMenuItem = new javax.swing.JMenuItem();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        calcularMenu.setMnemonic('f');
        calcularMenu.setText("Calcular");

        quadradoMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_Q, java.awt.event.InputEvent.CTRL_MASK));
        quadradoMenuItem.setMnemonic('o');
        quadradoMenuItem.setText("Quadrado");
        quadradoMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                quadradoMenuItemActionPerformed(evt);
            }
        });
        calcularMenu.add(quadradoMenuItem);

        retanguloMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_R, java.awt.event.InputEvent.CTRL_MASK));
        retanguloMenuItem.setMnemonic('s');
        retanguloMenuItem.setText("Retângulo");
        retanguloMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                retanguloMenuItemActionPerformed(evt);
            }
        });
        calcularMenu.add(retanguloMenuItem);

        trianguloMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        trianguloMenuItem.setMnemonic('a');
        trianguloMenuItem.setText("Triângulo");
        trianguloMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                trianguloMenuItemActionPerformed(evt);
            }
        });
        calcularMenu.add(trianguloMenuItem);

        circuloMenuItem.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        circuloMenuItem.setText("Circulo");
        circuloMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                circuloMenuItemActionPerformed(evt);
            }
        });
        calcularMenu.add(circuloMenuItem);

        exitMenuItem.setMnemonic('x');
        exitMenuItem.setText("Sair");
        exitMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                exitMenuItemActionPerformed(evt);
            }
        });
        calcularMenu.add(exitMenuItem);

        menuBar.add(calcularMenu);

        ajudaMenu.setMnemonic('h');
        ajudaMenu.setText("Ajuda");
        ajudaMenu.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ajudaMenuActionPerformed(evt);
            }
        });

        formulasMenuItem.setText("Fórmulas");
        formulasMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                formulasMenuItemActionPerformed(evt);
            }
        });
        ajudaMenu.add(formulasMenuItem);

        sobreMenuItem.setText("Sobre");
        sobreMenuItem.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                sobreMenuItemActionPerformed(evt);
            }
        });
        ajudaMenu.add(sobreMenuItem);

        menuBar.add(ajudaMenu);

        setJMenuBar(menuBar);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 614, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(desktopPane, javax.swing.GroupLayout.DEFAULT_SIZE, 405, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void exitMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitMenuItemActionPerformed
        System.exit(0);
    }//GEN-LAST:event_exitMenuItemActionPerformed

private void quadradoMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_quadradoMenuItemActionPerformed
    quadradoForm.setVisible(true);   
}//GEN-LAST:event_quadradoMenuItemActionPerformed

private void sobreMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_sobreMenuItemActionPerformed
    sobreForm.setVisible(true);      
}//GEN-LAST:event_sobreMenuItemActionPerformed

private void circuloMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_circuloMenuItemActionPerformed
    circuloForm.setVisible(true);
}//GEN-LAST:event_circuloMenuItemActionPerformed

private void trianguloMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_trianguloMenuItemActionPerformed
    trianguloForm.setVisible(true);
}//GEN-LAST:event_trianguloMenuItemActionPerformed

private void retanguloMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_retanguloMenuItemActionPerformed
    retanguloForm.setVisible(true);
}//GEN-LAST:event_retanguloMenuItemActionPerformed

private void ajudaMenuActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ajudaMenuActionPerformed
    JOptionPane.showMessageDialog(null, "Teste");
}//GEN-LAST:event_ajudaMenuActionPerformed

private void formulasMenuItemActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_formulasMenuItemActionPerformed
        //Utilização do factory para evitar a instanciação de varia classes, intanciando assim apenas a IFormula
        String[] opcoes = new String[]{"Quadrado","Retângulo","Triângulo","Circulo"};        
        String op = String.valueOf(JOptionPane.showInputDialog(this, "Escolha a fórmula desejada:","Fórmulas",JOptionPane.INFORMATION_MESSAGE,null,opcoes,""));
        try {
            IFormula figura = FormulasCreator.detectarFigura(op);
            JOptionPane.showMessageDialog(this, figura.getFormula(), op, WIDTH);
        } catch (IllegalArgumentException e) {
            System.out.println(e.getClass().getCanonicalName() + ": " + e.getMessage());
        }
}//GEN-LAST:event_formulasMenuItemActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(PrincipalMDI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(PrincipalMDI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(PrincipalMDI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(PrincipalMDI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            @Override
            public void run() {
                new PrincipalMDI().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JMenu ajudaMenu;
    private javax.swing.JMenu calcularMenu;
    private javax.swing.JMenuItem circuloMenuItem;
    private javax.swing.JDesktopPane desktopPane;
    private javax.swing.JMenuItem exitMenuItem;
    private javax.swing.JMenuItem formulasMenuItem;
    private javax.swing.JMenuBar menuBar;
    private javax.swing.JMenuItem quadradoMenuItem;
    private javax.swing.JMenuItem retanguloMenuItem;
    private javax.swing.JMenuItem sobreMenuItem;
    private javax.swing.JMenuItem trianguloMenuItem;
    // End of variables declaration//GEN-END:variables
}
